﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.MyCharacters.HeroDisplayer;
using _MetalSlug.MyCharacters.Characters;
using Microsoft.Xna.Framework.Graphics;
using _MetalSlug.MyCharacters.BuilderFactories;
using Microsoft.Xna.Framework;
using _MetalSlug.MyCharacters.Characters.Guns;

namespace _MetalSlug.MyCharacters.CharacterBuilers
{
    public class Builder
    {
        MyBuilderFactory Factory;
        public Builder(MyBuilderFactory ownerFactory)
        {
                Factory = ownerFactory;
        }

        public Displayer BuildDefault(Vector2 _Size)
        {
            Displayer newDisplayer = new Displayer(_Size);
            List<Texture2D> lstBodyTextures, lstFootTextures;
            lstBodyTextures = Factory.GetBody(Gun.TYPE.MINIGUN, MyCharacter.CURRENT_ACTIVITY.STAND);
            newDisplayer.Body = new HeroBody(lstBodyTextures, _Size);
            newDisplayer.Body.CurrentActivity = MyCharacter.CURRENT_ACTIVITY.STAND;
            newDisplayer.Body.CurrentGun = Gun.TYPE.MINIGUN;

            lstFootTextures = Factory.GetFoot(MyCharacter.CURRENT_ACTIVITY.STAND);
            newDisplayer.Foot = new HeroFoot(lstFootTextures, _Size);
            newDisplayer.Foot.CurrentActivity = MyCharacter.CURRENT_ACTIVITY.STAND;
            newDisplayer.Size = newDisplayer.Body.Size;
            return newDisplayer;
        }

        public Displayer Build(MyCharacter.CURRENT_ACTIVITY currentActivity, Gun.TYPE currentGun, Displayer currentDisplayer)
        {
            HeroBody currentBody = currentDisplayer.Body;
            HeroFoot currentFoot = currentDisplayer.Foot;
            
            if(currentBody.CurrentActivity != currentActivity || currentBody.CurrentGun != currentGun)
            {
                List<Texture2D> lstBodyTextures = Factory.GetBody(currentGun, currentActivity);
                
                if(lstBodyTextures != null)
                {
                    currentDisplayer.Body.Textures = lstBodyTextures;
                    currentDisplayer.Body.CurrentActivity = currentActivity;
                    currentDisplayer.Body.CurrentGun = currentGun;
                }
            }

            if (currentFoot.CurrentActivity != currentActivity)
            {
                List<Texture2D> lstFootTextures = Factory.GetFoot(currentActivity);

                if (lstFootTextures != null)
                {
                    currentDisplayer.Foot.Textures = lstFootTextures;
                    currentDisplayer.Foot.CurrentActivity = currentActivity;
                }
                
            }

            return currentDisplayer;

        }

    }
}
